package com.example.exceldemo.liteflowComponent.qh;

import cn.hutool.core.date.DateUtil;
import com.deepoove.poi.config.Configure;
import com.example.exceldemo.constants.ReqMgrConstants;
import com.example.exceldemo.liteflowComponent.common.GenerateDocuments;
import com.example.exceldemo.model.DemoContext;
import com.example.exceldemo.model.ReqAnalysisSpecificationDTO;
import com.example.exceldemo.model.ReqInfoDTO;
import com.example.exceldemo.util.WordUtil;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import lombok.extern.slf4j.Slf4j;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 生成需求概要文档  青海
 * @author yangwb8
 * @Date 2025/5/17 04:06
 */
@LiteflowComponent("qh_three")
@Slf4j
public class GenerateQhThreeDocuments extends GenerateDocuments {
    @Override
    public void processReqDocuments(ReqInfoDTO reqInfo, String templateDir, String reqOutputDir, Map<String, String> settings) {
        log.info("开始生成需求概要文档");
        //
        DemoContext deoContext = getDemoContext();
        ReqAnalysisSpecificationDTO reqAnalysisDTO = deoContext.getReqAnalysisDTO();

        Configure baseConfig = createBaseConfig(getPolicy());

        // 修改：直接使用模板文件名，无需构建完整路径
        String templateFileName = ReqMgrConstants.TEMPLATE_DESIGIN;
        Path outputPath = Paths.get(reqOutputDir, getDocName(reqInfo));
        String provCode = reqInfo.getProvCode();
        // 统一使用类路径方式生成文档
        WordUtil.generateWordFileByOS(provCode,templateFileName, outputPath.toString(), reqAnalysisDTO, baseConfig);
        log.info("需求分析文档生成完成");
    }

    @Override
    public String getDocName(ReqInfoDTO reqInfo) {
        return  "青海-BSS-" + DateUtil.format(LocalDateTime.now(), "yyyyMM") + "-" + reqInfo.getReqNo() + "-"
                + reqInfo.getReqName()+"_需求概要设计说明书.docx";
    }
}
